import 'dart:ui';

import 'package:yuan_hang_app/res/w_colors.dart';

import '../../../utils/common_utils.dart';
import '../../../utils/string_utils.dart';
import '../../../widget/w_toast.dart';

class TrialDriveModel {
  //已预约、签约中、待开始、试驾中、已结束、已取消
  static Map exchangeStatus(status) {
    Map map = {"color": WColors.green, "pressText": "", "openFlag": true};

    if (status == "已预约") {
      map = {"color": WColors.green, "pressText": "登记", "openFlag": true};
    } else if (status == "签约中") {
      map = {"color": WColors.orange, "pressText": "", "openFlag": true};
    } else if (status == "待开始") {
      map = {"color": WColors.C628AF4, "pressText": "开始", "openFlag": true};
    } else if (status == "试驾中") {
      map = {"color": WColors.redMain, "pressText": "结束", "openFlag": true};
    } else if (status == "已结束") {
      map = {"color": WColors.subTextColor, "pressText": "", "openFlag": false};
    } else if (status == "已取消") {
      map = {"color": WColors.CCCCCCC, "pressText": "", "openFlag": false};
    }
    return map;
  }

  //校验表单必填项
  static bool check(Map params) {
    //校验试驾类型
    if (CommonUtils.isEmptyOrNull(params["driveType"])) {
      Toast.toast("请输入试驾类型");
      return false;
    }

    //校验试驾方式
    if (CommonUtils.isEmptyOrNull(params["driveMethod"])) {
      Toast.toast("请输入试驾方式");
      return false;
    }

    //校验接待顾问
    if (CommonUtils.isEmptyOrNull(params["saleMan"].toString())) {
      Toast.toast("请输入接待顾问");
      return false;
    }

    //校验客户名称
    if (CommonUtils.isEmptyOrNull(params["customerName"])) {
      Toast.toast("请输入客户名称");
      return false;
    }

    //校验手机号
    var flag = StringUtils.isChinaPhoneLegal(params["phone"]);
    if (!flag) {
      Toast.toast("请输入正确的手机号码");
      return false;
    }
    //校验证件号必填
    if (CommonUtils.isEmptyOrNull(params["idNo"])) {
      Toast.toast("请输入身份证号码");
      return false;
    }
    //校验证件号是否正确
    var isCardId = CommonUtils.isCardId(params["idNo"]);
    if (!isCardId) {
      Toast.toast("请输入正确的身份证号码");
      return false;
    }
    //校验客户地址必填
    if (CommonUtils.isEmptyOrNull(params["address"])) {
      Toast.toast("请输入客户地址");
      return false;
    }
    //校验驾驶证 如果为试乘则不用校验
    if (CommonUtils.isEmptyOrNull(params["frontPictureList"].toString())) {
      Toast.toast("请上传驾驶证正面");
      return false;
    }
    if (CommonUtils.isEmptyOrNull(params["backPictureList"].toString())){
      Toast.toast("请上传驾驶证反面");
      return false;
    }
    if (CommonUtils.isEmptyOrNull(params["driveVehicle"].toString())|| params["driveVehicle"].length==1){
      Toast.toast("请选择试驾车辆");
      return false;
    }

    return true;
  }
}
